import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';

export namespace CommissionRecordApi {
  /** 统一提成记录信息 */
  export interface CommissionRecord {
    id: number; // 主键ID
    recordCode?: string; // 记录编码
    staffId?: number; // 员工ID
    staffType?: string; // 员工类型
    commissionType?: string; // 提成类型
    baseAmount?: number; // 基础金额
    commissionRate?: number; // 提成比例
    commissionAmount?: number; // 提成金额
    bonusAmount: number; // 奖励金额
    adjustmentAmount: number; // 调整金额
    totalCommission: number; // 总提成金额
    businessId?: number; // 业务ID
    businessType?: string; // 业务类型
    businessDate?: string | Dayjs; // 业务日期
    ruleId: number; // 提成规则ID
    policyId: number; // 策略ID
    decisionLogId: number; // 决策日志ID
    status: string; // 状态
    confirmTime: string | Dayjs; // 确认时间
    payTime: string | Dayjs; // 发放时间
    calculationDetails: string; // 计算详情
    groupId: number; // 集团ID
    storeId: number; // 门店ID
    orgId: number; // 组织ID
    customerId: number; // 客户ID
    customerName: string; // 客户姓名
    serviceId: number; // 服务ID
    serviceName: string; // 服务名称
  }
}

/** 查询统一提成记录分页 */
export function getCommissionRecordPage(params: PageParam) {
  return requestClient.get<PageResult<CommissionRecordApi.CommissionRecord>>('/spa/commission-record/page', { params });
}

/** 查询统一提成记录详情 */
export function getCommissionRecord(id: number) {
  return requestClient.get<CommissionRecordApi.CommissionRecord>(`/spa/commission-record/get?id=${id}`);
}

/** 新增统一提成记录 */
export function createCommissionRecord(data: CommissionRecordApi.CommissionRecord) {
  return requestClient.post('/spa/commission-record/create', data);
}

/** 修改统一提成记录 */
export function updateCommissionRecord(data: CommissionRecordApi.CommissionRecord) {
  return requestClient.put('/spa/commission-record/update', data);
}

/** 删除统一提成记录 */
export function deleteCommissionRecord(id: number) {
  return requestClient.delete(`/spa/commission-record/delete?id=${id}`);
}


/** 导出统一提成记录 */
export function exportCommissionRecord(params: any) {
  return requestClient.download('/spa/commission-record/export-excel', { params });
}

